const { default: mongoose } = require('mongoose');
const { User } = require('../../../models')

function modifyLike(io, socket, data, callback) { // 点赞数量 ++
    User.updateOne({ phone: data }, { $inc: { upvote: 1 } })
        .catch(err => console.log(err))
}

function modifyNickname(io, socket, data, callback) {
    let { user_id,  nickname } = data;

    if (!mongoose.Types.ObjectId.isValid(user_id)) {
        return callback({ status_code: 400, info: '无效的用户ID' });
    }

    User.updateOne({ _id: user_id }, { $set: { nickname } })
        .then(() => callback({ status_code: 200, info: '昵称修改成功' }))
        .catch(err => callback({ status_code: 401, info: '昵称修改失败', err }))
}

module.exports = {
    modifyLike,
    modifyNickname
}